package com.ziyun.erp.web.modules.goods.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.goods.entity.GoodsEntity;
import com.ziyun.erp.modules.goods.entity.GoodsHotsellEntity;
import com.ziyun.erp.modules.goods.service.GoodsHotsellService;
import com.ziyun.erp.modules.goods.service.GoodsService;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 热销展示表
 *
 * @author 'luqy'
 * @email
 * @date 2018-12-07 10:03:47
 */
@RestController
@RequestMapping("goods/goodshotsell")
public class GoodsHotsellController {
    @Autowired
    private GoodsHotsellService goodsHotsellService;
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goods:goodshotsell:list")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = goodsHotsellService.queryPage(params);
        List<GoodsEntity> goodsList = goodsService.selectGoodsList(params);
        return R.ok().put("page", page).put("goodsList", goodsList);

    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("goods:goodshotsell:info")
    public R info(@PathVariable("id") Integer id) {
        GoodsHotsellEntity goodsHotsell = goodsHotsellService.selectById(id);

        return R.ok().put("goodsHotsell", goodsHotsell);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goods:goodshotsell:save")
    public R save(@RequestBody GoodsHotsellEntity goodsHotsell) {
        R result = goodsHotsellService.saveInfo(goodsHotsell);

        return result;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goods:goodshotsell:update")
    public R update(@RequestBody GoodsHotsellEntity goodsHotsell) {
        ValidatorUtils.validateEntity(goodsHotsell);
        goodsHotsellService.updateById(goodsHotsell);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
  /*  @RequestMapping("/delete")
    @RequiresPermissions("goods:goodshotsell:delete")
    public R deleteUpdate(@RequestParam("id") Integer id){
        goodsHotsellService.deleteUpdate(id);

        return R.ok();
    }*/

}
